$(function() {  
    FastClick.attach(document.body);  
});
//轮播图
$(document).ready(function(){
	$dragBln = false;
	//获取轮播图数据
	var type=$("#type").val();
	if(type!=null && type!=undefined){
		$.ajax({
			type:"post",
			url:rootPath+"/advert/getAdvertList",
			data:{'amount':5,'type':type},
			success:function(data){
				if(data.resultSuccess){
					//alert(data.resultSuccess);
					var adverts=data.data;
					if(adverts!=null && adverts!=""){
						var str1='';
						var buttonStr='';
						var j = 0;
						//alert(JSON.stringify(adverts));
						$(".homeCarousel_img").empty();
						$(".dot").empty();
						$.each(adverts,function(i,item){
							debugger;
							str1+='<img src="'+item.img+'" alt="'+(j+1)+'"/>';
							if(i==0){
								buttonStr+='<span class="on"></span>';
							}else{
								buttonStr+='<span></span>';
							}
							j++;
						});
						str1+='<img src="'+adverts[0].img+'" alt="'+j+1+'"/>';
						$(".homeCarousel_img").append(str1);
						$(".dot").append(buttonStr);
					}
					
					//设置jQuery轮播图数据
					$(".homeCarousel_img").touchSlider({
						flexible : true,
						speed : 100,
						btn_prev : $("#btn_prev"),
						btn_next : $("#btn_next"),
						paging : $(".dot span"),
						counter : function (e){
							$(".dot span").removeClass("on").eq(e.current-1).addClass("on");
						}
					});
					
					$(".homeCarousel_img").bind("mousedown", function() {
						$dragBln = false;
					});
					
					$(".homeCarousel_img").bind("dragstart", function() {
						$dragBln = true;
					});
					
					$(document).on("click",".homeCarousel_img a",function(){
						if($dragBln) {
							return false;
						}
					});
					
					timer = setInterval(function(){
						$("#btn_next").click();
					}, 5000);
					
					$(".carousel").hover(function(){
						clearInterval(timer);
					},function(){
						timer = setInterval(function(){
							$("#btn_next").click();
						},5000);
					});
					
					$(".homeCarousel_img").bind("touchstart",function(){
						clearInterval(timer);
					}).bind("touchend", function(){
						timer = setInterval(function(){
							$("#btn_next").click();
						}, 5000);
					});
				}
			}
		});
	}
});





